package com.wlyuan.index.infrastructure.jobhandler;


import com.wlyuan.index.api.IOrderIndexService;
import com.wlyuan.index.api.dto.order.OrderReindexDTO;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author yuanjie
 * 重建10分钟之内的创建的订单 每10分钟执行一次
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class OrderReindexScanJobHandler extends IJobHandler {
    private final IOrderIndexService orderIndexService;

    @Override
    @XxlJob("OrderReindexScanJob")
    public void execute() {
        var reindex = new OrderReindexDTO();
        var timeStart = LocalDateTime.now().plusMinutes(-10);
        reindex.setCreateAtBegin(timeStart);
        if (logger.isDebugEnabled()) {
            logger.debug("执行重建订单索引任务: {}", reindex);
        }
        orderIndexService.reindex(reindex);
    }
}
